package com.ruoyi.buss.report.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.buss.utils.DateUtilss;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.buss.report.mapper.ReportDhyxLsbMapper;
import com.ruoyi.buss.report.domain.ReportDhyxLsb;
import com.ruoyi.buss.report.service.IReportDhyxLsbService;

/**
 * 单户用信100w以下的个人贷款Service业务层处理
 * 
 * @author sxy
 * @date 2021-07-16
 */
@Service
public class ReportDhyxLsbServiceImpl implements IReportDhyxLsbService 
{
    @Autowired
    private ReportDhyxLsbMapper reportDhyxLsbMapper;

    /**
     * 查询单户用信100w以下的个人贷款
     * 
     * @param sjrq 单户用信100w以下的个人贷款ID
     * @return 单户用信100w以下的个人贷款
     */
    @Override
    public ReportDhyxLsb selectReportDhyxLsbById(String sjrq)
    {
        return reportDhyxLsbMapper.selectReportDhyxLsbById(sjrq);
    }

    /**
     * 查询单户用信100w以下的个人贷款列表
     * 
     * @param reportDhyxLsb 单户用信100w以下的个人贷款
     * @return 单户用信100w以下的个人贷款
     */
    @Override
    public List<ReportDhyxLsb> selectReportDhyxLsbList(ReportDhyxLsb reportDhyxLsb)
    {
        return reportDhyxLsbMapper.selectReportDhyxLsbList(reportDhyxLsb);
    }

    /**
     * 新增单户用信100w以下的个人贷款
     * 
     * @param reportDhyxLsb 单户用信100w以下的个人贷款
     * @return 结果
     */
    @Override
    public int insertReportDhyxLsb(ReportDhyxLsb reportDhyxLsb)
    {
        reportDhyxLsb.setCreateTime(DateUtils.getNowDate());
        return reportDhyxLsbMapper.insertReportDhyxLsb(reportDhyxLsb);
    }

    /**
     * 修改单户用信100w以下的个人贷款
     * 
     * @param reportDhyxLsb 单户用信100w以下的个人贷款
     * @return 结果
     */
    @Override
    public int updateReportDhyxLsb(ReportDhyxLsb reportDhyxLsb)
    {
        return reportDhyxLsbMapper.updateReportDhyxLsb(reportDhyxLsb);
    }

    /**
     * 批量删除单户用信100w以下的个人贷款
     * 
     * @param sjrqs 需要删除的单户用信100w以下的个人贷款ID
     * @return 结果
     */
    @Override
    public int deleteReportDhyxLsbByIds(String[] sjrqs)
    {
        return reportDhyxLsbMapper.deleteReportDhyxLsbByIds(sjrqs);
    }

    /**
     * 删除单户用信100w以下的个人贷款信息
     * 
     * @param sjrq 单户用信100w以下的个人贷款ID
     * @return 结果
     */
    @Override
    public int deleteReportDhyxLsbById(String sjrq)
    {
        return reportDhyxLsbMapper.deleteReportDhyxLsbById(sjrq);
    }

    @Override
    public List<ReportDhyxLsb> grdhyx(ReportDhyxLsb reportDhyxLsb, LoginUser userInfo) {
        List<ReportDhyxLsb> doList = new ArrayList<ReportDhyxLsb>();

        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        if (!StringUtils.isEmpty(reportDhyxLsb.getSjrq())) {
            if ("9999".equals(reportDhyxLsb.getSjrq())) {
                reportDhyxLsb.setSjrq("");
            }
            sjrqs = new ArrayList<String>();
            String sjrq = reportDhyxLsb.getSjrq();
            sjrq = sjrq.replace("-", "");
            sjrqs.add(sjrq);
        }
        reportDhyxLsb.setSjrqs(sjrqs);
        doList = reportDhyxLsbMapper.grdhyx(reportDhyxLsb);
        return doList;
    }

    @Override
    public List<ReportDhyxLsb> grdhyxhz(ReportDhyxLsb reportDhyxLsb, LoginUser userInfo) {
        List<ReportDhyxLsb> doList = new ArrayList<ReportDhyxLsb>();

        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        if (!StringUtils.isEmpty(reportDhyxLsb.getSjrq())) {
            if ("9999".equals(reportDhyxLsb.getSjrq())) {
                reportDhyxLsb.setSjrq("");
            }
            sjrqs = new ArrayList<String>();
            String sjrq = reportDhyxLsb.getSjrq();
            sjrq = sjrq.replace("-", "");
            sjrqs.add(sjrq);
        }
        reportDhyxLsb.setSjrqs(sjrqs);
        doList = reportDhyxLsbMapper.grdhyxhz(reportDhyxLsb);

        return doList;
    }
}
